<template>
    <div>
        账号：<input type="text" v-model="admin"><br> 
        密码：<input type="password" v-model="pass">
        <button @click="login()">登录</button>
    </div>
</template>

<script setup lang="ts">
import { doLogin } from "@/apis/user"
import { ref } from "vue";
import router from "@/router";

const admin = ref<string>('')
const pass = ref<string>('')

const login = () => {
    doLogin({
        adminname: admin.value, 
        password: pass.value
    }).then(res => {
        console.log(res)
        if(res.data.code == 200){
            router.push('/home')
        } else {
            alert("账号或者密码错误重新登录")
        }
    }).catch(error => {
        console.error('登录失败:', error)
        alert("登录失败，请重试")
    })
}
</script>

<style scoped>

</style>